home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / PROGEDIT / 0748.ZIP / KEYVAL.C < prev    next >
Text File  |  1986-02-19  |  1KB  |  35 lines

  1. /* KEYVAL.C - when user presses a key, displays the numerical code generated */
  2.  
  3. #include <stdio.h>
  4. #include <dos.h>
  5.  
  6. main()
  7. {
  8.   int  c;
  9.  
  10.   printf("KEYVAL - find code generated for a key  (press ESC to exit)\n");
  11.   while ((c = kb()) != 27)
  12.     printf("%d\n", c);
  13. }
  14.  
  15.  
  16. kb()
  17. {
  18.   register int c, scan_code;
  19.   union REGS r;
  20.  
  21.   r.h.ah = 00;           /* Interrupt 16H service 0 */
  22.   int86(0x16, &r, &r);       /*  fetches the keystroke. */
  23.   if ((c = r.h.al) == 0)     /* It's a special key, so  */
  24.     c = r.h.ah | 0x80;       /*  turn on the high bit.  */
  25.  
  26.   /* This section tests if we pressed a <SHIFT> keypad key. */
  27.   /* Among the codes not used (see keys.h) are 133-142 and  */
  28.   /* 154-157. We map scan codes 71-83 into these keystrokes.*/
  29.   else if ((scan_code = r.h.ah) >= 71 && scan_code <= 83)
  30.     c = scan_code + ((scan_code <= 80) ? 62 : 73);
  31.   else if (scan_code == 55)         /* hit the <PrtSc> key */
  32.     c = 157;
  33.   return(c);         /* returns int c (ascii value of key)  */
  34. }
  35.